package com.backend.demo1.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.backend.demo1.mapper.MinorMemberMapper;
import com.backend.demo1.models.MinorMember;

@Service
public class MinorMemberService {
    @Autowired
    private MinorMemberMapper MinorMemberMapper;

    // 插入成年会员
    public void insert(MinorMember minormember) {
        MinorMemberMapper.insert(minormember);
    }

    // 根据 ID 查找会员
    public MinorMember findById(Long id) {
        return MinorMemberMapper.findById(id);
    }

    // 获取所有成年会员
    public List<MinorMember> findAll() {
        return MinorMemberMapper.findAll();
    }

    // 更新会员信息
    public void update(MinorMember minormember) {
        MinorMemberMapper.update(minormember);
    }

    // 删除会员信息
    public void deleteById(Long id) {
        if (MinorMemberMapper.findById(id) == null) {
            throw new IllegalArgumentException("No record found with ID: " + id);
        }
        MinorMemberMapper.deleteById(id);
    }

    // 检查是否已存在该会员（通过 userId）
    public boolean existsByUserId(Long userId) {
        return MinorMemberMapper.existsByUserId(userId) > 0;
    }
}
